package com.lnlyj.navigation.demo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.lnlyj.navigation.LnlyjNavigationBar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Wanglei on 2019/11/26.
 */

public class JavaActivity extends AppCompatActivity {

    TextView textView;
    LnlyjNavigationBar bar;

    List<CharSequence> titles = new ArrayList<>();
    List<Integer> icons = new ArrayList<>();

    int addIndex = 4;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_java);

        textView = findViewById(R.id.text);
        bar = findViewById(R.id.nav_bar);

        bar.setTabSelectedColor(getResources().getColor(R.color.colorPrimary));
        bar.setTabDefaultColor(getResources().getColor(R.color.colorAccent));

        bar.addTabChangeListener(new LnlyjNavigationBar.OnTabChangeListener() {
            @Override
            public void onTabChange(int oldIndex, int newIndex) {
                textView.setText(String.format("当前选中的是：%s", titles.get(newIndex)));
            }
        });

        for (int i = 0; i < 4; i++) {
            titles.add("页面" + (i + 1));
            icons.add(R.drawable.ic_directions_bike_black);
        }


        bar.setupWithTitlesAndIcons(titles, icons);
    }

    public void onAddTabSelectedClick(View view) {
        titles.add("新增" + addIndex);
        icons.add(R.mipmap.ic_launcher);
        bar.addTab("新增" + addIndex, R.drawable.ic_directions_bike_black, addIndex++, true);
    }

    public void onAddTabUnSelectedClick(View view) {
        titles.add("新增" + addIndex);
        icons.add(R.mipmap.ic_launcher);
        bar.addTab("新增" + addIndex, R.drawable.ic_directions_bike_black, addIndex++, false);
    }
}
